package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entitry.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author 张伟奇
 * @Date 2021/7/17 19:24
 * @description
 * @Version 1.0
 **/
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper,SpecParam> implements SpecParamService  {
   @Autowired
   private SpecParamMapper specParamMapper;


    @Override
    public List<SpecParamDTO> listSpecParamByCategoryId(Long categoryId, Long groupId, Boolean searching) {
        List<SpecParam> specParamsList = this.specParamMapper
                .selectList(new QueryWrapper<SpecParam>()
                        .eq(categoryId != null, "category_id", categoryId)
                        .eq(groupId != null, "group_id", groupId)
                        .eq(searching != null, "searching", searching));
        return SpecParamDTO.convertEntityList(specParamsList);
    }

    @Override
    @Transactional
    public void saveSpecParam(SpecParamDTO specParamDTO) {
        this.specParamMapper.insert(specParamDTO.toEntity(SpecParam.class));
    }

    @Override
    @Transactional
    public void updateSpecParam(SpecParamDTO specParamDTO) {
        this.specParamMapper.updateById(specParamDTO.toEntity(SpecParam.class));
    }
}
